package com.xunfang.controller;

import com.xunfang.bean.Result;
import com.xunfang.exception.MyException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yellow Doctor
 * @date 2025-09-18
 * @desc https://blog.csdn.net/hekai7217
 */
@RestController
public class TestController {


    @GetMapping("/test/{id}")
    public Result test(@PathVariable Integer id){

        if (id == 0){
            int a = 10 /id; //这里会出异常   数学算术异常

        }
        if (id == 3){
            String a = null;
            int length = a.length();   // NullException  对象没有实例化
        }

        if (id == 4){
            //手动抛出自定义异常
            throw new MyException("我是自己自首的  异常....");
        }

        if (id >5){                 //正常
            return Result.ok();
        }

        return Result.ok();
    }

}
